//
//  OKLOLViewCell.m
//  ZLFastDoctor
//
//  Created by answer on 16/5/27.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "OKLOLViewCell.h"
#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS
#import <Masonry/Masonry.h>
#import <UIImageView+WebCache.h>

@interface OKLOLViewCell ()
// 播放按钮
@property(nonatomic, strong) UIImageView * start;
// 图片
@property(nonatomic, strong) UIImageView * icon;
// 主标题
@property(nonatomic, copy) UILabel * bigTitle;
// 主播名称
@property(nonatomic, copy) UILabel * name;
// 在线人数
@property(nonatomic, copy) UILabel * onLineCount;

@end

@implementation OKLOLViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        // 添加子控件
        [self addSubview:self.icon];
        [self addSubview:self.bigTitle];
        [self addSubview:self.name];
        [self addSubview:self.onLineCount];
        
    }
    return self;
}

// 在模型set方法中赋值
- (void)setModel:(OKLOLModel *)model {
    
    _model = model;
    
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.thumb]];
    self.bigTitle.text = model.title;
    
    self.name.text = model.nick;
    self.name.font = [UIFont systemFontOfSize:14];
    self.name.textColor = [UIColor grayColor];
    
    self.onLineCount.text = [NSString stringWithFormat:@"在线人数:%@",model.view];
    self.onLineCount.font = [UIFont systemFontOfSize:14];
    self.onLineCount.textColor = [UIColor grayColor];
}

// 布局子控件
- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    [self.icon makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.top.equalTo(self).offset(5);
        make.right.equalTo(self).offset(-5);
        make.height.equalTo(@185);
    }];
    
    [self.start makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@40);
        make.center.equalTo(self.icon);
    }];
    
    [self.bigTitle makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self).offset(6);
        make.top.equalTo(self.icon.bottom).offset(5);
    }];
    
    [self.name makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self).offset(6);
        make.bottom.equalTo(self).offset(-6);
    }];
    
    [self.onLineCount makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self).offset(-6);
        make.bottom.equalTo(self).offset(-6);
    }];
}

- (UIImageView *)start {
    
    if (_start == nil) {
        _start = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"start001"]];
        // 播放按钮切圆角
        _start.layer.cornerRadius = 20;
        _start.layer.masksToBounds = YES;
        
        [self.icon addSubview:_start];
    }
    return _start;
}

- (UIImageView *)icon {
    
    if (_icon == nil) {
        _icon = [[UIImageView alloc]init];
    }
    return _icon;
}

- (UILabel *)bigTitle {
    
    if (_bigTitle == nil) {
        _bigTitle = [[UILabel alloc]init];
    }
    return _bigTitle;
}

- (UILabel *)name {
    
    if (_name == nil) {
        _name = [[UILabel alloc]init];
    }
    return _name;
}

- (UILabel *)onLineCount {
    
    if (_onLineCount == nil) {
        _onLineCount = [[UILabel alloc]init];
    }
    return _onLineCount;
}

@end
